<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
    <div class="panelBar" th:fragment="pagination(url)">
        <!-- 处理页数小于等于7 的情况 -->
        <ul th:if="${(pageInfo.pages le 7)&&(pageInfo.pages gt 0)}" class="pagination">
            <li th:if="${pageInfo.pageNum eq 1}" class="page-item disabled"><a class="page-link" href="#">上一页</a></li>
            <li th:if="${pageInfo.pageNum gt 1}" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${pageInfo.pageNum}-1,size=${pageInfo.pageSize})}">上一页</a>
            </li>

            <li th:each="index:${#numbers.sequence(1,pageInfo.pages)}" th:classappend="${index eq page}?'active'" class="page-item">
                <a th:href="@{${url}(page=${index},size=${pageInfo.pageSize})}" class="page-link"  th:text="${index}"></a>
            </li>

            <li th:if="${pageInfo.pageNum eq pageInfo.pages}" class="page-item disabled"><a class="page-link" href="#">下一页</a></li>
            <li th:if="${pageInfo.pageNum lt pageInfo.pages}" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${pageInfo.pageNum}+1,size=${pageInfo.pageSize})}">下一页</a>
            </li>
        </ul>

        <!-- 处理页数大于7 的情况 -->
        <ul th:if="${pageInfo.pages gt 7}" class="pagination">
            <li th:if="${pageInfo.pageNum eq 1}" class="page-item disabled"><a class="page-link" href="#">上一页</a></li>
            <li th:if="${pageInfo.pageNum gt 1}" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${pageInfo.pageNum}-1,size=${pageInfo.pageSize})}">上一页</a>
            </li>

            <!-- 首页 -->
            <li th:classappend="${pageInfo.pageNum eq 1}?'active'" class="page-item">
                <a class="page-link" th:href="@{${url}(page=1,size=${pageInfo.pageSize})}">1</a>
            </li>

            <!-- 当前页面小于等于4 -->
            <li th:if="${pageInfo.pageNum le 4}" th:each="index:${#numbers.sequence(2,5)}" th:classappend="${index eq page}?'active'" class="page-item">
                <a th:href="@{${url}(page=${index},size=${pageInfo.pageSize})}" class="page-link"  th:text="${index}"></a>
            </li>
            <li th:if="${pageInfo.pageNum le 4}" class="page-item">
                <a  class="page-link" th:href="@{${url}(page=6,size=${pageInfo.pageSize})}">...</a>
            </li>

            <!-- 最后一页与当前页面之差小于等于3 -->
            <li th:if="${pageInfo.pages - pageInfo.pageNum le 3}" class="page-item">
                <a  class="page-link" th:href="@{${url}(page=${pageInfo.pages - 5},size=${pageInfo.pageSize})}">...</a>
            </li>
            <li th:if="${pageInfo.pages - pageInfo.pageNum le 3}" th:each="index:${#numbers.sequence(pageInfo.pages - 4,pageInfo.pages - 1)}" th:classappend="${index eq pageInfo.pageNum}?'active'" class="page-item">
                <a th:href="@{${url}(page=${index},size=${pageInfo.pageSize})}" class="page-link"  th:text="${index}"></a>
            </li>

            <!-- 最后一页与当前页面之差大于3 且当前页面大于4 -->
            <li th:if="${(pageInfo.pageNum gt 4) && (pageInfo.pages - pageInfo.pageNum gt 3)}" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${pageInfo.pageNum - 2},size=${pageInfo.pageSize})}">...</a>
            </li>
            <li th:if="${(pageInfo.pageNum gt 4) && (pageInfo.pages - pageInfo.pageNum gt 3)}" th:each="index:${#numbers.sequence( pageInfo.pageNum - 1,pageInfo.pageNum + 1)}" th:classappend="${index eq pageInfo.pageNum }?'active'" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${index},size=${pageInfo.pageSize})}" th:text="${index}"></a>
            </li>
            <li th:if="${(pageInfo.pageNum gt 4) && (pageInfo.pages - pageInfo.pageNum gt 3)}" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${pageInfo.pageNum + 2},size=${pageInfo.pageSize})}">...</a>
            </li>

            <!-- 尾页 -->
            <li th:classappend="${pageInfo.pageNum eq pageInfo.pages}?'active'" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${pageInfo.pages},size=${pageInfo.pageSize})}" th:text="${pageInfo.pages}">尾页</a>
            </li>

            <li th:if="${pageInfo.pageNum eq pageInfo.pages}" class="page-item disabled"><a class="page-link" href="#">下一页</a></li>
            <li th:if="${pageInfo.pageNum lt pageInfo.pages}" class="page-item">
                <a class="page-link" th:href="@{${url}(page=${pageInfo.pageNum}+1,size=${pageInfo.pageSize})}">下一页</a>
            </li>
        </ul>
    </div>
</body>
</html>